using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using EPiServer.Shell.Gadgets;
using AnalyticsGadget.Models;

namespace AnalyticsGadget.Controllers
{
    [Gadget(Name = "Statistics - Visitors", Title = "Visitor Statistics", IconUrl = "Content/analytics.png")]
    public class StatisticsVisitorsController : BaseStatisticsController
    {
        protected override Report GetReport(string profileID, Timespan timespan)
        {
            ReportQuery query = new ReportQuery(profileID, MetricType.Visits);

            switch(timespan)
            {
                case Timespan.Year:
                    query.AddDimension(DimensionType.Month);
                    query.AddSortBy(DimensionType.Month, SortDirection.Ascending);            
                    break;
                case Timespan.Month:
                    query.AddDimension(DimensionType.Date);
                    query.AddSortBy(DimensionType.Date, SortDirection.Ascending);
                    break;
                case Timespan.Week:
                    query.AddDimension(DimensionType.Date);
                    query.AddSortBy(DimensionType.Date, SortDirection.Ascending);
                    break;
                case Timespan.Day:
                    query.AddDimension(DimensionType.Hour);
                    query.AddSortBy(DimensionType.Hour, SortDirection.Ascending);
                    break;
            }

            //query.AddSortBy(MetricType.Visits, SortDirection.Descending);
            query.SetTimespan(timespan);

            return StatisticsHelper.GetReport(query);
        }

    }
}
